﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BanHangCshap.Class
{
    class NhomKhachHangNCC:Database
    {
        #region ***** Fields & Properties *****
        private string _manhomkhncc;
        public string manhomkhncc
        {
            get
            {
                return _manhomkhncc;
            }
            set
            {
                _manhomkhncc = value;
            }
        }
        private string _tennhomkhncc;
        public string tennhomkhncc
        {
            get
            {
                return _tennhomkhncc;
            }
            set
            {
                _tennhomkhncc = value;
            }
        }
        
        
        #endregion

        #region ***** Init Methods *****
        public NhomKhachHangNCC()
        {
        }
        public NhomKhachHangNCC(string manhomkhncc)
        {
            string sql = "select * from NhomKhachHangNCC where manhomkhncc = '" + manhomkhncc + "'";
            foreach (DataRow dr in getDataTable(sql).Rows)
            {
                this.manhomkhncc = manhomkhncc;
                this.tennhomkhncc = dr["tennhomkhncc"].ToString().Trim();
            }
           
        }
        //public NhomKhachHangNCC(int manhomkhncc, string tennhomkhncc, int loainhomkhncc)
        //{
        //    this.manhomkhncc = manhomkhncc;
        //    this.tennhomkhncc = tennhomkhncc;
        //    this.loainhomkhncc = loainhomkhncc;
        //}
        #endregion
        public Boolean isExistNhomKhachHangNCC(string manhomkhncc)
        {
            string sql = "select manhomkhncc from NhomKhachHangNCC where manhomkhncc = '" + manhomkhncc + "'";
            return isExist(sql);
        }
        public DataTable layDSNhomKhachHangNCC()
        {
            string sql = "select manhomkhncc, tennhomkhncc from NhomKhachHangNCC where manhomkhncc <> 'MD' ";
            return getDataTable(sql);
        }
        public DataTable layDSKhachHangNCC(string manhomkhncc)
        {
            string sql = "select * from KhachHangNCC where manhomkhncc = '" + manhomkhncc + "' and makhncc <> 'MD'";
            return getDataTable(sql);
        }
        public DataTable layThongTinKhachHang(string makhncc)
        {
            string sql = "select * from KhachHangNCC where makhncc = '" + makhncc + "'";
            return getDataTable(sql);
        }
        public Boolean themNhomKhachHangNCC()
        {
            string sql = "insert into NhomKhachHangNCC(manhomkhncc,tennhomkhncc) values ('" + manhomkhncc + "',N'" + tennhomkhncc + "')";
            return executeQuery(sql);
        }
        public Boolean suaNhomKhachHangNCC()
        {
            string sql = "update NhomKhachHangNCC set  tennhomkhncc = N'" + tennhomkhncc + "' where manhomkhncc = '" + manhomkhncc + "'";
            return executeQuery(sql);
        }
        public Boolean xoaNhomKhachHangNCC(string manhomkhncc)
        {
            string sql = "delete NhomKhachHangNCC  where manhomkhncc = '" + manhomkhncc + "'";
            return executeQuery(sql);
        }
        public string taoMaNhomKhNCC()
        {
            string sql = "select max(convert(int,manhomkhncc)) from NhomKhachHangNCC";
            return string.Format("{0,3:000}", getNumberValue(sql) + 1);
        }

    }
}
